/**
 * 2
 *  
 * @Author : roryrywang
 * @DateTime : 24-9-5 下午4:00
 */

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }

    int f[n + 1][x];
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j < x; ++j) {
            if (i == 0) {
                if (j == 0)f[i][j] = 0;
                else f[i][j] = 0x3f3f3f3f;
                continue;
            }
            f[i][j] = f[i - 1][(j - a[i] + x) % x];
            for (int k = 0; k <=j ; ++k) {
                f[i][j] = min(f[i][j], f[i][j - k] + k);
            }
        }
        for (int j = 0; j < x; ++j) {
            if (j == 0)continue;
            f[i][j] = min(f[i][j], f[i][(j + a[i]) % x] + 1);
        }
    }

    int res = 0x3f3f3f3f;
    for (int i = 0; i <= n; ++i) {
        res = min(res, f[i][0]);
    }

    cout << res;

    return 0;
}

//3 5
//1 3 3